﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AssemblyExtensions.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the AssemblyExtensions type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Reflection
{
    using System;
    using System.Reflection;

    public static class AssemblyExtensions
    {
        public static string GetShortName(this Assembly instance)
        {
            var name = instance.FullName;

            var index = name.IndexOf(',');
            if (index >= 0)
            {
                name = name.Substring(0, index);
            }

            return name.Trim();
        }

        public static Uri GetComponentUri(this Assembly instance, string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
        
            if (path.Length == 0 || path[0] != '/')
            {
                path = '/' + path;
            }

            return new Uri(string.Format("{0};component{1}", instance.GetShortName(), path), UriKind.Relative);
        }
    }
}
